package com.you.atlas.biz.member.service.impl;

import com.you.atlas.biz.member.service.FollowService;
import com.you.member.dal.dao.FollowDAO;
import com.you.member.dal.dao.dataobject.FollowDO;

public class FollowServiceImpl implements FollowService {

    private FollowDAO followDAO;

    public void setFollowDAO(FollowDAO followDAO) {
        this.followDAO = followDAO;
    }

    @Override
    public boolean follow(Long masterMmeberId, Long fansMemberId) {
        if(masterMmeberId == fansMemberId){
            return false;
        }
        if(followDAO.findByMemberId(masterMmeberId, fansMemberId)!=null){
            return false;
        }
        FollowDO followDO = new FollowDO();
        followDO.setFansMemberId(fansMemberId);
        followDO.setMasterMemberId(masterMmeberId);
        followDAO.create(followDO);

        return true;
    }

    @Override
    public boolean cancelFollow(Long masterMemberId, Long fansMemberId) {
        
        return followDAO.delete(masterMemberId, fansMemberId)!=null;
    }
}
